//
//  YHYDesignerPersonController.m
//  Home
//
//  Created by 吴军虎吴军虎 on 16/6/6.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "YHYDesignerPersonController.h"
#import "WSCustomPickerView.h"
#import "WSRewardCell.h"
#import "WSAddCVLastCell.h"
#import "WSAddCVModel.h"
#import "QRCodeReaderViewController.h"
#import "WSAddCVItem.h"
#import "WSAddCVItemTwo.h"
#import "WSAddCVTypeSubCell.h"
#import "WSAddLineView.h"
#import "WSAddCVHeadView.h"
#import "WSAddWorkHeadView.h"
#import "DCPaymentView.h"
#import "WSRequirementView.h"
#import "YHYAddStudyViewController.h"
#import "YHYAddWorkViewController.h"
#import "WSShopInfoNextView.h"
#import "YHYJobViewController.h"
typedef enum : NSUInteger {
    DATEPICKER = 1,
    ADDRESSPICKER,
} PICKERTYPE;

typedef enum : NSUInteger {
    ISKID = 1,
    ISNOTKID,
    ISNOTSELECT,
} KID;

@interface YHYDesignerPersonController ()<UICollectionViewDelegate, UICollectionViewDataSource, WSCustomPickerViewDelegate, WSRewardCellDelegate,WSShopInfoNextViewDelegate,YHYJobNumberArrDelegate> {
    
    BOOL isHasType;
    NSMutableArray *saveArr;
    NSIndexPath *tempIndexPath;
}

@property (nonatomic, strong) UICollectionView *collectionView;
/**
 *  数据
 */
@property (nonatomic, strong) NSMutableArray *cellArr;
@property (nonatomic, strong) NSIndexPath *indexPath;
/**
 *  判断是否是小孩
 */
@property (nonatomic, assign) KID isKid;
/**
 *  选择器
 */
@property (nonatomic, strong) WSCustomPickerView *customPicker;
@property (nonatomic, strong) WSAddCVModel *model;
@property (nonatomic, strong) NSMutableArray *keyArr;
@property (nonatomic, strong) QRCodeReaderViewController *qrCodeReaderVC;


@end

@implementation YHYDesignerPersonController


- (void)viewWillAppear:(BOOL)animated {
    
    self.navigationController.navigationBarHidden = NO;
    self.tabBarController.tabBar.hidden=YES;
    
    self.title = @"个人信息";
    
}

-(void) viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden=NO;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.model = [[WSAddCVModel alloc] init];
    _isKid = ISNOTKID;
    isHasType = NO;
    [self initData];
    
    
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(Back:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.minimumInteritemSpacing = 0;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, -44.0, SCREEN_WIDTH, SCREEN_HEIGHT - 40) collectionViewLayout:flowLayout];
    self.collectionView.showsVerticalScrollIndicator = NO;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.view addSubview:_collectionView];
    [self.collectionView registerClass:[WSAddCVItem class] forCellWithReuseIdentifier:@"addCVCell"];
    [self.collectionView registerClass:[WSAddCVItemTwo class] forCellWithReuseIdentifier:@"addCVItem"];
    [self.collectionView registerClass:[WSAddCVTypeSubCell class] forCellWithReuseIdentifier:@"selectCell"];
    [self.collectionView registerClass:[WSAddLineView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"addLineView"];
    [self.collectionView registerClass:[WSAddCVLastCell class]  forCellWithReuseIdentifier:@"addCVLastCell"];
    
    [self.collectionView registerClass:[WSAddCVHeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"addHeadView"];
    [self.collectionView registerClass:[WSAddWorkHeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"addWorkHeadView"];
    [self.collectionView registerClass:[WSRewardCell class] forCellWithReuseIdentifier:@"rewardCell"];
}


#pragma makr -- collectionView delegate && dataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    if (section > 1 - (_isKid == ISKID) && section < _cellArr.count - 2) {
        
        if (isHasType && section == 3 - (_isKid == ISKID)) {
            return _model.modelType.count;
        }
        NSMutableArray *tempArr = [[[_cellArr[section] firstObject] allValues] firstObject];
        return tempArr.count;
    }
    if (section == _cellArr.count - 1) {
        return 2;
    }
    return [_cellArr[section] count];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return _cellArr.count;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    
    if (section < 2 - (_isKid == ISKID)) {
        return 0;
    } else {
        return 5;
    }
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    
    if ((section == 1 && !(_isKid == ISKID)) || section >= _cellArr.count - 2) {
        NSLog(@"uuuu=%ld",_cellArr.count - 2);
        return CGSizeZero;
    }
    if (section == 5) {
        return CGSizeMake(SCREEN_WIDTH, 80);
    }
    
    return CGSizeMake(SCREEN_WIDTH, 44);
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
    if (section == _cellArr.count - 1 ) {
        return CGSizeMake(SCREEN_WIDTH,0);
    }
    return CGSizeMake(SCREEN_WIDTH, 10);
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    
    if (kind == UICollectionElementKindSectionFooter) {
    
        WSAddLineView *view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"addLineView" forIndexPath:indexPath];
        
        return view;
    }
    
    if (indexPath.section == 5) {
        WSAddCVHeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"addHeadView" forIndexPath:indexPath];
        view.alpha = 1;
        view.backgroundColor = [UIColor redColor];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headViewAction:)];
        [view addGestureRecognizer:tap];
        return view;
    }
    
    else {
        if (indexPath.section == 0) {
            WSAddCVHeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"addHeadView" forIndexPath:indexPath];
            view.alpha = 0;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headViewAction:)];
            [view addGestureRecognizer:tap];
            return view;
        } else if ((indexPath.section == 1 && !(_isKid == ISKID)) || indexPath.section >= _cellArr.count - 2) {
            
            //            WSAddWorkHeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"addWorkHeadView" forIndexPath:indexPath];
            //            NSDictionary *dic = [_cellArr[indexPath.section] firstObject];
            //            NSString *titleStr = [[dic allKeys] firstObject];
            //            view.titleStr = titleStr;
            //            return view;
            return nil;
        }
        WSAddWorkHeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"addWorkHeadView" forIndexPath:indexPath];
        //        view.backgroundColor = [UIColor redColor];
        NSDictionary *dic = [_cellArr[indexPath.section] firstObject];
        NSString *titleStr = [[dic allKeys] firstObject];
        view.titleStr = titleStr;
        return view;
    }
    
 
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section <  2 - (_isKid == ISKID) || indexPath.section > _cellArr.count - 3) {
        
        if (indexPath.section == 4) {
            return CGSizeMake(SCREEN_WIDTH, 80 * AUTO_WIDTH);
        }
        if (indexPath.section == 5) {
            return CGSizeMake(SCREEN_WIDTH, 80 * AUTO_WIDTH);
        }
        return CGSizeMake(SCREEN_WIDTH, 44);
    }
    
    
    else {
        if (isHasType && indexPath.section == 3 - (_isKid == ISKID)) {
            return CGSizeMake(SCREEN_WIDTH, 44);
        }
        return CGSizeMake(80 * AUTO_WIDTH, 30 * AUTO_WIDTH);
    }
    
    
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    
    if (section < 2 - (_isKid == ISKID) || section >= _cellArr.count - 2 || (isHasType && section == 3)) {
        return UIEdgeInsetsZero;
    }
    else {
        return UIEdgeInsetsMake(5 * AUTO_WIDTH, 135 / 4 * AUTO_WIDTH, 5 * AUTO_WIDTH, 135 / 4 * AUTO_WIDTH);
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section < 2 - (_isKid == ISKID) || indexPath.section >= _cellArr.count - 2) {
     
        if (indexPath.section == _cellArr.count-1  &&
            indexPath.row == 0) {
            WSAddCVItemTwo *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"addCVItem" forIndexPath:indexPath];
            
            NSDictionary *dic = [_cellArr[indexPath.section] objectAtIndex:indexPath.row];
            cell.titleStr = [[dic allKeys] firstObject];
            
            if ([cell.titleStr isEqualToString:@"北京大学"]) {
                
                cell.type = 2;
            } else {
                
                cell.type = 1;
            }
            
            if (indexPath.section < 2 - (_isKid == ISKID)) {
                cell.content = [_model valueForKey:[_keyArr[indexPath.section] objectAtIndex:indexPath.row]];
            }
            
            
            return cell;
           
        }
        
        if (indexPath.section == _cellArr.count-1  &&
            indexPath.row == 1) {
            
            WSAddCVItemTwo *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"addCVItem" forIndexPath:indexPath];
            cell.addLabel.backgroundColor = GH;
            cell.backgroundColor = LV;
            return cell;
        
        }
        
        
        WSAddCVItem *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"addCVCell" forIndexPath:indexPath];
       
        NSDictionary *dic = [_cellArr[indexPath.section] objectAtIndex:indexPath.row];
        cell.titleStr = [[dic allKeys] firstObject];
        
        if ([cell.titleStr isEqualToString:@"蓝觉"]) {
           
            cell.type = 2;
        } else {
            
            cell.type = 1;
        }
        
        if (indexPath.section < 2 - (_isKid == ISKID)) {
            cell.content = [_model valueForKey:[_keyArr[indexPath.section] objectAtIndex:indexPath.row]];
        }
        
        return cell;
    }
     else if (indexPath.section < 2 - (_isKid == ISKID) || indexPath.section >= _cellArr.count - 2) {
        
         
        if (indexPath.section == _cellArr.count-1){
            WSAddCVItemTwo *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"addCVItem" forIndexPath:indexPath];
            
            NSDictionary *dic = [_cellArr[indexPath.section] objectAtIndex:indexPath.row];
            cell.titleStr = [[dic allKeys] firstObject];
            
            if ([cell.titleStr isEqualToString:@"北京大学"]) {
                
                cell.type = 2;
            } else {
                
                cell.type = 1;
            }
            
            if (indexPath.section < 2 - (_isKid == ISKID)) {
                cell.content = [_model valueForKey:[_keyArr[indexPath.section] objectAtIndex:indexPath.row]];
            }
            
            
            return cell;
        }
        WSAddCVItem *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"addCVCell" forIndexPath:indexPath];
        
        NSDictionary *dic = [_cellArr[indexPath.section] objectAtIndex:indexPath.row];
        cell.titleStr = [[dic allKeys] firstObject];
        
        if ([cell.titleStr isEqualToString:@"蓝觉"]) {
            
            cell.type = 2;
        } else {
            
            cell.type = 1;
        }
        
        if (indexPath.section < 2 - (_isKid == ISKID)) {
            cell.content = [_model valueForKey:[_keyArr[indexPath.section] objectAtIndex:indexPath.row]];
        }
        
        return cell;
    }
    

    
    else {
        
        if (isHasType && indexPath.section == 3 - (_isKid == ISKID)) {
            
            

        }
        WSAddCVTypeSubCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"selectCell" forIndexPath:indexPath];
        
        if (indexPath.section == 2 - (_isKid == ISKID)) {
            UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longAction:)];
            [cell.contentLabel addGestureRecognizer:longPress];
        }
        
        NSDictionary *dic = [_cellArr[indexPath.section] firstObject] ;
        NSArray *tempArr = [[dic allValues] firstObject];
        
    
        cell.contentStr = tempArr[indexPath.row];
        if ([cell.contentStr isEqualToString:_model.mainType]) {
            [cell changeBorderColor:YES];
        } else {
            [cell changeBorderColor:NO];
        }
        
        NSMutableArray *modelArr = [_model valueForKey:_keyArr[indexPath.section]];
        if ([modelArr containsObject:cell.contentStr]) {
            [cell changeColor:YES];
        } else {
            [cell changeColor:NO];
        }
        
        return cell;
    }
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"nmb == %@",indexPath);
    _indexPath = indexPath;
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            //我的职业
            
            YHYJobViewController *job = [YHYJobViewController new];
            
            job.delegate = self;
            
            [self.navigationController pushViewController:job animated:YES];
        }
        if (indexPath.row == 3) {
           
            
            
            [self createDatePicker:1];
            [self.customPicker showPicker];
            
        } else {
            
            NSDictionary *dataDic = [[self.cellArr objectAtIndex:0] objectAtIndex:indexPath.row];
            NSArray *dataArr = [[dataDic allValues] firstObject];
            if (indexPath.row == 1 || indexPath.row == 2) {
                if (_isKid == ISKID) {
                    [self createCustomPicker:dataArr[1]];
                }
                else if (_isKid == ISNOTKID) {
                    [self createCustomPicker:dataArr[0]];
                }
                else {
                    //如果没有选择，弹出提示
                }
            }
            else {
                [self createCustomPicker:dataArr];
            }
        }
    }
    else if (indexPath.section == 1 && !(_isKid == ISKID)) {
        
        NSDictionary *dataDic = [[self.cellArr objectAtIndex:1] objectAtIndex:indexPath.row];
        NSArray *dataArr = [[dataDic allValues] firstObject];
        
        [self createCustomPicker:dataArr];
        
    } else if (indexPath.section == _cellArr.count - 1) {
        
        YHYAddStudyViewController *study=[[YHYAddStudyViewController alloc]init];
        [self.navigationController pushViewController:study animated:YES];
        
        
    } else if (indexPath.section == _cellArr.count - 2) {
        
//        YHYAddWorkViewController  *work=[[YHYAddWorkViewController alloc]init];
//        [self.navigationController pushViewController:work animated:YES];
        
    } else if (indexPath.section == 3 - (_isKid == ISKID) && isHasType) {
        
    } else {
        
        NSDictionary *dic = [_cellArr[indexPath.section]    objectAtIndex:0];
        NSArray *tempArr = [[dic allValues] firstObject];
        NSMutableArray *modelArr = [_model valueForKey:_keyArr[indexPath.section]];
        if ([tempArr[indexPath.row] isEqualToString:@"+"]) {
            
            [self addItem];
            return;
        } else {
            if ([modelArr containsObject:tempArr[indexPath.row]]) {
                [_model.rewardArr removeObjectAtIndex:[modelArr indexOfObject:tempArr[indexPath.row]]];
                [modelArr removeObject:tempArr[indexPath.row]];
                if ([tempArr[indexPath.row] isEqualToString:_model.mainType]) {
                    _model.mainType = nil;
                }
            } else {
                [modelArr addObject:tempArr[indexPath.row]];
                [_model.rewardArr addObject:@"0"];
            }
            
            if (_model.modelType.count != 0 && isHasType != YES) {
                isHasType = YES;
                
                tempIndexPath = indexPath;
                _model.mainType = tempArr[indexPath.row];
                [self.collectionView reloadData];
                
                [_cellArr insertObject:[NSArray arrayWithObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"", @"报酬", nil]] atIndex:3];
                [_keyArr insertObject:@"" atIndex:3];
            } else if (_model.modelType.count == 0 && isHasType == YES) {
                isHasType = NO;
                [self.collectionView reloadData];
                [_cellArr removeObjectAtIndex:3];
                [_keyArr removeObjectAtIndex:3];
            }
            if (indexPath.section == 2 - (_isKid == ISKID) && _model.rewardArr.count != 0) {
                
//                [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:1]];
            }
            
            if (indexPath.section == 3) {
               [self.collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
            }
            
            
        }
        
        
    }
    
    if (indexPath.section == 0 || indexPath.section == 1) {
        NSDictionary *dic = [_cellArr[indexPath.section] objectAtIndex:indexPath.row];
        NSString *title = [[dic allKeys] firstObject];
        self.customPicker.titleStr = title;
    }
}

#pragma mark -
#pragma mark -- 选择器
- (void)createDatePicker:(PICKERTYPE)pickerType {
    
    if (pickerType == DATEPICKER) {
        self.customPicker = nil;
        self.customPicker = [[WSCustomPickerView alloc] initWithFrame:[UIScreen mainScreen].bounds type:1];
        self.customPicker.delegate = self;
        [self.view addSubview:_customPicker];
    }
    else {
        self.customPicker = nil;
        self.customPicker = [[WSCustomPickerView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        self.customPicker.delegate = self;
        [self.view addSubview:_customPicker];
    }
}

- (void)createCustomPicker:(NSArray *)dataArr {
    
    self.customPicker = nil;
    self.customPicker = [[WSCustomPickerView alloc] initWithFrame:[UIScreen mainScreen].bounds dataArr:dataArr];
    self.customPicker.delegate = self;
    [self.view addSubview:self.customPicker];
    [self.customPicker showPicker];
}

#pragma mark -- 选择器返回数据
- (void)sendAddressInfo:(NSString *)address {
    
    
    if (_indexPath.row == 0) {
        if ([address isEqualToString:@"童模"]) {
            if (_isKid != ISKID) {
                _isKid = ISKID;
                _model.height = @"";
                _model.weight = @"";
                saveArr = _cellArr[1];
                [_cellArr removeObjectAtIndex:1];
                [_keyArr removeObjectAtIndex:1];
            }
        }
        else {
            if (_isKid != ISNOTKID) {
                if (_isKid != ISNOTSELECT) {
                    [_cellArr insertObject:saveArr atIndex:1];
                    [_keyArr insertObject:[NSArray arrayWithObjects:@"chest", @"waistline", @"hipMeasurement", @"shoeSize", nil] atIndex:1];
                }
                _isKid = ISNOTKID;
                _model.height = @"";
                _model.weight = @"";
            }
        }
        
    }
    
    [_model setValue:address forKey:[_keyArr[_indexPath.section] objectAtIndex:_indexPath.row]];
    if (_indexPath.section == 0 &&
        _indexPath.row == 0) {
        
        [self.collectionView reloadData];
    } else {
        
        [self.collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:_indexPath]];
    }
}

- (void)addItem {
    
    DCPaymentView *payAlert = [[DCPaymentView alloc] init];
    payAlert.title = [NSString stringWithFormat:@"请输入"];
    [payAlert show];
    payAlert.completeHandle = ^(NSString *inputPwd) {
        
        NSMutableDictionary *tempDic = [self.cellArr[_indexPath.section] objectAtIndex:0];
        NSMutableArray *tempArr = [[tempDic allValues] firstObject];
        [tempArr insertObject:inputPwd atIndex:tempArr.count - 1];
        
        [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:_indexPath.section]];
    };
}

-(void)Back:(UIBarButtonItem *)goback{
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -- 报酬代理方法
- (void)buttonClickWith:(BUTTONCLICK)btn label:(UILabel *)label {
    
    if (btn == BUTTONCLICKCONTENT) {
        
        WSRequirementView *requirementV = [[WSRequirementView alloc] init];
        requirementV.titleLabel.text = @"单位时间";
        requirementV.dataArr = [NSArray arrayWithObjects:@"每天", @"每小时", @"每件", nil];
        [requirementV showView];
    } else {
        
        DCPaymentView *payAlert = [[DCPaymentView alloc] init];
        payAlert.title = [NSString stringWithFormat:@"报酬"];
        [payAlert setTextFieldKeyBordToNum];
        //payAlert.maxTextNum = 5;
        [payAlert show];
        payAlert.completeHandle = ^(NSString *inputPwd) {
            
            [self.model.rewardArr addObject:inputPwd];
            label.text = [NSString stringWithFormat:@"%@元", inputPwd];
        };
    }
}

#pragma mark -- 长按
- (void)longAction:(UILongPressGestureRecognizer *)longPress {
    
    UILabel *label = (UILabel *)longPress.view;
    if ([_model.modelType containsObject:label.text]) {
        
        WSAddCVTypeSubCell *cell = (WSAddCVTypeSubCell *)label.superview.superview;
        [cell changeBorderColor:YES];
        _model.mainType = label.text;
        if (tempIndexPath) {
            [_collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:tempIndexPath]];
        }
        WSAddCVTypeSubCell *tempCell = (WSAddCVTypeSubCell *)[_collectionView cellForItemAtIndexPath:tempIndexPath];
        if (![tempCell.contentStr isEqualToString:cell.contentStr]) {
            
            tempIndexPath = [_collectionView indexPathForCell:cell];
            NSLog(@"%lu %lu", [_collectionView indexPathForCell:cell].section, [_collectionView indexPathForCell:cell].row);
        }
        
    }
    
}

#pragma mark -- 扫码
- (void)headViewAction:(UITapGestureRecognizer *)rap {
    
    NSArray *types = @[AVMetadataObjectTypeQRCode];
    
    self.qrCodeReaderVC = [QRCodeReaderViewController readerWithMetadataObjectTypes:types];
    
    
    self.qrCodeReaderVC.delegate = self;
    
    
    [self.qrCodeReaderVC setCompletionWithBlock:^(NSString *resultAsString) {
        //    [self dismissViewControllerAnimated:YES completion:^{
        //            NSLog(@"----------------%@", resultAsString);
        
        //            if (resultAsString.length != 0) {
        //
        //                TZYTwoDimensionDodeViewController *web = [[TZYTwoDimensionDodeViewController alloc]init];
        //
        //                //把扫到的url传递给下一个页面
        //                web.url = resultAsString;
        //                [self.navigationController pushViewController:web animated:YES];
        //            }
        
        //        }];
    }];
    
    [self presentViewController:self.qrCodeReaderVC animated:YES completion:NULL];
}

//读取结果后
- (void)reader:(QRCodeReaderViewController *)reader didScanResult:(NSString *)result
{
    [self dismissViewControllerAnimated:YES completion:^{
        NSLog(@"%@", result);
        
    }];
}


//取消返回
- (void)readerDidCancel:(QRCodeReaderViewController *)reader
{
    [self dismissViewControllerAnimated:YES completion:NULL];
}

#pragma mark -- 初始化数据
- (void)initData {
    
    _keyArr = [NSMutableArray arrayWithObjects:[NSArray arrayWithObjects:@"selfLabel", @"height", @"weight", @"employYear", @"country", nil], [NSArray arrayWithObjects:@"chest", @"waistline", @"hipMeasurement", @"shoeSize", nil], @"modelType", @"style", @"experience", @"temp", nil];
    
    NSString *nameStr = @"NModel";
    
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:nameStr ofType:@"plist"];
    NSArray *tempArr = [[NSArray alloc] initWithContentsOfFile:plistPath];
    self.cellArr = [[NSMutableArray alloc] initWithArray:tempArr];
    NSMutableArray *firstArr = [NSMutableArray arrayWithArray:[tempArr objectAtIndex:3]];
    
    for (int i = 0; i < firstArr.count; i++) {
        NSDictionary *dic = firstArr[i];
        NSString *titleName = [[dic allKeys] firstObject];
        if ([titleName isEqualToString:@"擅长风格"] ||
            [titleName isEqualToString:@"商业摄影"] ||
            [titleName isEqualToString:@"影视妆"] ||
            [titleName isEqualToString:@"男装设计"]) {
            NSMutableArray *newArr = [NSMutableArray arrayWithArray:[[dic allValues] firstObject]];
            [firstArr removeObjectAtIndex:i];
            [firstArr insertObject:[NSMutableDictionary dictionaryWithObject:newArr forKey:titleName] atIndex:i];
        }
    }
    
    [self.cellArr removeObjectAtIndex:3];
    [self.cellArr insertObject:firstArr atIndex:3];
    
}



@end
